package com.learn.order.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.learn.order.entity.OrderTbl;
import com.learn.order.feign.AccountClient;
import com.learn.order.mapper.OrderTblMapper;
import com.learn.order.service.IOrderTblService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zhaofa
 * @since 2019-11-12
 */
@Service
public class OrderTblServiceImpl extends ServiceImpl<OrderTblMapper, OrderTbl> implements IOrderTblService {
    @Autowired
    private AccountClient accountFeignClient;
    @Resource
    private OrderTblMapper orderTblMapper;

    @Override
    @Transactional
    public void create(String userId, String commodityCode, Integer count) {
        BigDecimal orderMoney = new BigDecimal(count).multiply(new BigDecimal(5));
        OrderTbl order = new OrderTbl();
        order.setUserId(userId);
        order.setCommodityCode(commodityCode);
        order.setCount(count);
        order.setMoney(orderMoney);
        orderTblMapper.insert(order);
        accountFeignClient.reduce(userId, orderMoney);


    }
}
